﻿using FastReport;
using Newtonsoft.Json.Linq;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;

namespace WinFormsApp1.TongShiWei.segmentationData
{
    public partial class SegmentationStatement2 : UIForm
    {
        public SegmentationStatement2()
        {
            InitializeComponent();
        }
        public string frx;
        private void designerControl1_Load(object sender, EventArgs e)
        {
            Report report = new Report();
            if (!string.IsNullOrWhiteSpace(frx))
                report.Load(frx);




            //var item = await HttpClientHelper.RequestUrl<object, ApiResultFY2<List<CheckInDeailDto>>>("http://localhost:5106/api/Reports/", "QueryCheckDetail", HttpClientHelper.MethodType.POST, check);

            //http://localhost:5106/api/Reports/QueryWhiteporkCollect
            string url = URLCommon.Url2 + @"/Tsw/ShowRKWeightData";
            HttpClient client = new HttpClient();
            RKWeighData_Now whitepork = new RKWeighData_Now();
            var content = new StringContent(JsonSerializer.Serialize<RKWeighData_Now>(whitepork));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var results = info["data"].Value<JArray>();
            //var results = info["data"].Value<JToken>();
            //var resultss = results["list"].Value<JArray>();

            //// 加载报表模板，这里假设模板文件是 "YourReportTemplate.frx"
            report.Load(@"../../../Reports\分割入库明细\demo.frx");

            DataSet ds = new DataSet();
            DataTable fr_dt = new DataTable();
            fr_dt.TableName = "baseInfos";
            fr_dt.Columns.Add("RKWeighId", typeof(String));//*****列名设置需要与标签模板一致*****
            fr_dt.Columns.Add("WeighNum", typeof(String));
            fr_dt.Columns.Add("GrossNum", typeof(String));
            fr_dt.Columns.Add("furNum", typeof(String));
            fr_dt.Columns.Add("suttleNum", typeof(String));
            fr_dt.Columns.Add("WeighTime", typeof(String));
            fr_dt.Columns.Add("PackName", typeof(String));
            fr_dt.Columns.Add("IsWeigh", typeof(String));
            fr_dt.Columns.Add("SumWeigh", typeof(String));
            fr_dt.Columns.Add("RKWeighNum", typeof(String));
            fr_dt.Columns.Add("UPCName", typeof(String));

            for (int i = 0; i < results.Count; i++)
            {
                fr_dt.Rows.Add(results[i]["RKWeighId"], results[i]["WeighNum"],
                    results[i]["GrossNum"], results[i]["furNum"],
                    results[i]["suttleNum"], results[i]["WeighTime"], results[i]["PackName"],
                    results[i]["IsWeigh"]
                    , results[i]["SumWeigh"], results[i]["RKWeighNum"], results[i]["UPCName"]);

            }
            ds.Tables.Add(fr_dt);
            report.RegisterData(ds);//将数据传递至标签模板

            //report.Print();//打印标签
            designerControl1.Report = report;
            //restore the design layout. Without this code, the designer tool windows will be unavailable
            designerControl1.RefreshLayout();
        }
        //显示分割称重入库表数据
        public class RKWeighData_Now
        {
            /// <summary>
            /// 分割称重入库ID
            /// </summary>
            public int RKWeighId { get; set; }
            /// <summary>
            /// 称重件数
            /// </summary>
            public int WeighNum { get; set; }
            /// <summary>
            /// 毛重
            /// </summary>
            public double GrossNum { get; set; }
            /// <summary>
            /// 皮重
            /// </summary>
            public double furNum { get; set; }
            /// <summary>
            /// 净重
            /// </summary>
            public double suttleNum { get; set; }
            /// <summary>
            /// 称重时间
            /// </summary>
            public DateTime WeighTime { get; set; }
            /// <summary>
            /// 包装名称
            /// </summary>
            public string PackName { get; set; } = string.Empty;
            /// <summary>
            /// 是否删除
            /// </summary>
            public bool IsWeigh { get; set; }
            /// <summary>
            /// 总重
            /// </summary>
            public double SumWeigh { get; set; }
            /// <summary>
            /// 入库数量
            /// </summary>
            public int RKWeighNum { get; set; }
            /// <summary>
            /// 商品代号
            /// </summary>
            public string UPCName { get; set; } = string.Empty;

        }
    }
}
